/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.model;

import java.util.List;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.table.AbstractTableModel;

import com.ruipengkj.bean.TGift;

/**
 * 说明：领取礼包Model
 * @Author：黄盛强
 * @Date：2012-03-19
 */
public class MemberGiftModel extends AbstractTableModel {

	private static final long serialVersionUID = 1L;
	private Vector<List<Object>> rowdatas=new Vector<List<Object>>();
	private Vector<String> columns = new Vector<String>();
	public MemberGiftModel(){
		columns.add("编号");
		columns.add("礼品名称");
		columns.add("换取积分");
		columns.add("货存");
		columns.add("截至时间");
		columns.add("操作1");
		columns.add("操作2");
		
		List<Object> row=new Vector<Object>();
		row.add("a");
		row.add("b");
		row.add("c");
		row.add("d");
		row.add("e");
		row.add("兑换");
		row.add("查看");
		rowdatas.add(row);
		
	}
	//获得行数
	public int getRowCount(){
		return rowdatas.size();
	}
	//获得列数
	public int getColumnCount(){
		return columns.size();
	}
	//获得单元格的值
	public Object getValueAt(int row,int column){
		
		return ((Vector)rowdatas.get(row)).get(column);
	}
	//获取列名
	public String getColumnName(int column){
		return (String)columns.get(column);
	}
	
	//获取列对应的类型
	public Class getColumnClass(int column){
		return column == (columns.size()-1) ? ImageIcon.class : Object.class;
	}
	//设置单元格是否可编辑
	public boolean isCellEditable(int rowIndex,int columnIndex){
		if(columns.size()-1==columnIndex||columns.size()-2==columnIndex){
			return true;
		}
		return false;
	}
	
	public void removeData(int row){
		rowdatas.remove(row);
	}
	
	
	
	//设置单元格的值
	public void setValueAt(Object aValue,int rowIndex,int columnIndex){
		//取出对应的记录
		Vector rowdata = (Vector)rowdatas.get(rowIndex);
		//删除原来的值
		rowdata.remove(columnIndex);
		//添加用户新修改的值
		rowdata.add(columnIndex,aValue);
	}


	public void setRowData(List<TGift> tGiftList) {
		rowdatas.clear();
		if(tGiftList != null && tGiftList.size() != 0){
			for(int i = 0;i < tGiftList.size();i++){
				TGift tGift = tGiftList.get(i);
				List<Object> row=new Vector<Object>();
				/*row.add(tGift.getGiftID());
				row.add(tGift.getSaler());
				row.add(tGift.getSendInfoID());
				row.add(tGift.getTUser().getUserName());
				row.add(tGift.getOperator());
				row.add(tGift.getPayedAmount());*/
				rowdatas.add(row);
			}
		}
	}
	public void clear() 
	{
		rowdatas.clear();
	}
}
